const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const resolve = dir => path.join(__dirname, dir);

module.exports = {
  entry: './src/index.jsx',
  output: {
    path: resolve('dist'),
    filename: 'main.js',
  },
  mode: 'development',
  devServer: {
    port: 2200,
    proxy: {
      '/open-apis': {
        target: 'https://open.feishu.cn',
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
      }
    }
  },
  module: {
    rules: [
      {
        test: /\.(c|le)ss$/i,
        use: ['style-loader', 'css-loader', 'less-loader']
      },
      {
        test: /\.(js|jsx|ts|tsx)$/,
        exclude: [resolve('./node_modules')],
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env', '@babel/preset-react'],
            }
          }
        ]
      },
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
    alias: {
      '@': resolve('./src'),
    }
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: resolve('./public/index.html')
    })
  ],
};
